﻿namespace jzgl.Windows
{
    using jzgl.Controller;
    using jzgl.Model;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Text.RegularExpressions;
    using System.Windows.Forms;

    public class UpdatePassword : Form
    {
        private Button btn_ChongZhi;
        private Button btn_XiuGai;
        private IContainer components = null;
        private GroupBox groupBox1;
        private Label label2;
        private Label label3;
        private Label label4;
        private Label label5;
        private Label label6;
        private Label label7;
        private Panel panel1;
        private TextBox txt_new1;
        private TextBox txt_new2;
        private TextBox txt_old;
        private SysUser user = new SysUser();
        private string user_name = "";
        private SysUserDB userDB = new SysUserDB();

        public UpdatePassword(string u_name)
        {
            this.InitializeComponent();
            this.user_name = u_name;
            this.txt_old.Focus();
        }

        private void btn_ChongZhi_Click(object sender, EventArgs e)
        {
            try
            {
                this.txt_new1.Text = this.txt_new2.Text = this.txt_old.Text = "";
            }
            catch (Exception)
            {
            }
        }

        private void btn_XiuGai_Click(object sender, EventArgs e)
        {
            try
            {
                Regex regex = new Regex(@"^[a-zA-Z]\w{1,17}$");
                if (this.txt_old.Text.Trim().Equals(""))
                {
                    MessageBox.Show("原密码不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (this.txt_new1.Text.Trim().Equals("") || this.txt_new2.Text.Trim().Equals(""))
                {
                    MessageBox.Show("新密码不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (!this.txt_new1.Text.Trim().Equals(this.txt_new2.Text.Trim()))
                {
                    MessageBox.Show("两次新密码不一致！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (regex.IsMatch(this.txt_new1.Text.Trim()) && regex.IsMatch(this.txt_new2.Text.Trim()))
                {
                    this.user._UserName = this.user_name;
                    this.user._UserPassword = this.txt_old.Text.Trim();
                    if (this.userDB.Is_UserExist(this.user) == 0)
                    {
                        MessageBox.Show("原密码错误！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else
                    {
                        this.user._UserPassword = this.txt_new1.Text.Trim();
                        if (this.userDB.Update_SystemUser_Password(this.user) != 0)
                        {
                            MessageBox.Show("修改成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("密码必须以字母开头，长度在2~18之间\n只能包含字符、数字和下划线！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            catch (Exception)
            {
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.panel1 = new Panel();
            this.groupBox1 = new GroupBox();
            this.label7 = new Label();
            this.label6 = new Label();
            this.label5 = new Label();
            this.txt_new2 = new TextBox();
            this.txt_new1 = new TextBox();
            this.txt_old = new TextBox();
            this.btn_ChongZhi = new Button();
            this.btn_XiuGai = new Button();
            this.label4 = new Label();
            this.label3 = new Label();
            this.label2 = new Label();
            this.panel1.SuspendLayout();
            this.groupBox1.SuspendLayout();
            base.SuspendLayout();
            this.panel1.Controls.Add(this.groupBox1);
            this.panel1.Location = new Point(7, 4);
            this.panel1.Name = "panel1";
            this.panel1.Size = new Size(0x11f, 0xdb);
            this.panel1.TabIndex = 0;
            this.groupBox1.Controls.Add(this.label7);
            this.groupBox1.Controls.Add(this.label6);
            this.groupBox1.Controls.Add(this.label5);
            this.groupBox1.Controls.Add(this.txt_new2);
            this.groupBox1.Controls.Add(this.txt_new1);
            this.groupBox1.Controls.Add(this.txt_old);
            this.groupBox1.Controls.Add(this.btn_ChongZhi);
            this.groupBox1.Controls.Add(this.btn_XiuGai);
            this.groupBox1.Controls.Add(this.label4);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Location = new Point(3, 8);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0x119, 0xd0);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "修改密码";
            this.label7.AutoSize = true;
            this.label7.ForeColor = Color.Red;
            this.label7.Location = new Point(0xf4, 0x6b);
            this.label7.Name = "label7";
            this.label7.Size = new Size(11, 12);
            this.label7.TabIndex = 11;
            this.label7.Text = "*";
            this.label6.AutoSize = true;
            this.label6.ForeColor = Color.Red;
            this.label6.Location = new Point(0xf5, 0x4b);
            this.label6.Name = "label6";
            this.label6.Size = new Size(11, 12);
            this.label6.TabIndex = 10;
            this.label6.Text = "*";
            this.label5.AutoSize = true;
            this.label5.ForeColor = Color.Red;
            this.label5.Location = new Point(0xf5, 0x2c);
            this.label5.Name = "label5";
            this.label5.Size = new Size(11, 12);
            this.label5.TabIndex = 9;
            this.label5.Text = "*";
            this.txt_new2.Location = new Point(0x6a, 0x66);
            this.txt_new2.Name = "txt_new2";
            this.txt_new2.Size = new Size(0x89, 0x15);
            this.txt_new2.TabIndex = 2;
            this.txt_new2.UseSystemPasswordChar = true;
            this.txt_new1.Location = new Point(0x6a, 0x47);
            this.txt_new1.Name = "txt_new1";
            this.txt_new1.Size = new Size(0x89, 0x15);
            this.txt_new1.TabIndex = 1;
            this.txt_new1.UseSystemPasswordChar = true;
            this.txt_old.Location = new Point(0x6a, 0x26);
            this.txt_old.Name = "txt_old";
            this.txt_old.Size = new Size(0x89, 0x15);
            this.txt_old.TabIndex = 0;
            this.txt_old.UseSystemPasswordChar = true;
            this.btn_ChongZhi.Location = new Point(0xa8, 0x9f);
            this.btn_ChongZhi.Name = "btn_ChongZhi";
            this.btn_ChongZhi.Size = new Size(0x3d, 0x17);
            this.btn_ChongZhi.TabIndex = 4;
            this.btn_ChongZhi.Text = "重置(&R)";
            this.btn_ChongZhi.UseVisualStyleBackColor = true;
            this.btn_ChongZhi.Click += new EventHandler(this.btn_ChongZhi_Click);
            this.btn_XiuGai.Location = new Point(0x4b, 0x9f);
            this.btn_XiuGai.Name = "btn_XiuGai";
            this.btn_XiuGai.Size = new Size(0x3e, 0x17);
            this.btn_XiuGai.TabIndex = 3;
            this.btn_XiuGai.Text = "确定(&O)";
            this.btn_XiuGai.UseVisualStyleBackColor = true;
            this.btn_XiuGai.Click += new EventHandler(this.btn_XiuGai_Click);
            this.label4.AutoSize = true;
            this.label4.Location = new Point(0x17, 0x6c);
            this.label4.Name = "label4";
            this.label4.Size = new Size(0x4d, 12);
            this.label4.TabIndex = 3;
            this.label4.Text = "确认新密码：";
            this.label3.AutoSize = true;
            this.label3.Location = new Point(0x2f, 0x4b);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x35, 12);
            this.label3.TabIndex = 2;
            this.label3.Text = "新密码：";
            this.label2.AutoSize = true;
            this.label2.Location = new Point(0x2f, 0x2b);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x35, 12);
            this.label2.TabIndex = 1;
            this.label2.Text = "原密码：";
            base.AutoScaleDimensions = new SizeF(6f, 12f);
//            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(300, 230);
            base.Controls.Add(this.panel1);
     //       base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            this.MaximumSize = new Size(0x132, 0x106);
            this.MinimumSize = new Size(0x132, 0x106);
            base.Name = "UpdatePassword";
            base.ShowIcon = false;
            base.StartPosition = FormStartPosition.CenterScreen;
            this.Text = "用户修改密码";
            base.Load += new EventHandler(this.UpdatePassword_Load);
            this.panel1.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            base.ResumeLayout(false);
        }

        private void UpdatePassword_Load(object sender, EventArgs e)
        {
            try
            {
            }
            catch (Exception)
            {
            }
        }
    }
}

